/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * StartWindow.java
 *
 * Created on 12/04/2011, 00:45:24
 */

package presentation.gui;

import common.network.messages.ErrorMessage;
import domain.ClientController;
import java.util.Arrays;
import javax.swing.JOptionPane;

import presentation.gui.notifications.NotificationsController;

/**
 *
 * @author ׳�׳™׳¨׳™
 */
public class StartWindow extends javax.swing.JFrame {

    ClientController controller;
    Forum _forum;

    /** Creates new form StartWindow */
    public StartWindow( ClientController clientController) {
        controller = clientController;
        setVisible(true);
        initComponents();
        new NotificationsController(clientController, clientController, this);
    }

    public Forum getForum(){
         _forum.clearFriends();
         _forum.setFriends();
         return _forum;
    }

    public void nonDisplayForum(){
        _forum.setVisible(false);
    }

    public void setForum(Forum forum){
        _forum=forum;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextField6 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jToggleButton1 = new javax.swing.JToggleButton();
        jPasswordField1 = new javax.swing.JPasswordField();
        jLabel2 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(null);

        jLabel4.setFont(new java.awt.Font("Kristen ITC", 1, 18));
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Password");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(330, 270, 100, 20);

        jLabel3.setFont(new java.awt.Font("Kristen ITC", 1, 18));
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("UserName");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(330, 210, 100, 25);

        jTextField6.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        jTextField6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField6ActionPerformed(evt);
            }
        });
        getContentPane().add(jTextField6);
        jTextField6.setBounds(450, 210, 120, 30);

        jButton1.setFont(new java.awt.Font("Kristen ITC", 1, 14)); // NOI18N
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/gui/pics/log_in.png"))); // NOI18N
        jButton1.setText("Login");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1);
        jButton1.setBounds(450, 350, 120, 30);

        jToggleButton1.setFont(new java.awt.Font("Kristen ITC", 1, 18));
        jToggleButton1.setForeground(new java.awt.Color(255, 0, 102));
        jToggleButton1.setText("Click here to register");
        jToggleButton1.setBorderPainted(false);
        jToggleButton1.setContentAreaFilled(false);
        jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jToggleButton1);
        jToggleButton1.setBounds(360, 450, 290, 33);

        jPasswordField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jPasswordField1ActionPerformed(evt);
            }
        });
        getContentPane().add(jPasswordField1);
        jPasswordField1.setBounds(450, 270, 120, 30);

        jLabel2.setFont(new java.awt.Font("Kristen ITC", 1, 18));
        jLabel2.setForeground(new java.awt.Color(255, 0, 102));
        jLabel2.setText("Don't you have an account?");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(370, 420, 290, 25);

        jLabel6.setFont(new java.awt.Font("Kristen ITC", 1, 36));
        jLabel6.setForeground(new java.awt.Color(255, 255, 255));
        jLabel6.setText("Forum System");
        getContentPane().add(jLabel6);
        jLabel6.setBounds(340, 80, 265, 49);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/gui/pics/wallpaper_by_J_Sheldon.jpg"))); // NOI18N
        jLabel1.setBorder(javax.swing.BorderFactory.createMatteBorder(5, 5, 5, 5, new java.awt.Color(0, 0, 0)));
        getContentPane().add(jLabel1);
        jLabel1.setBounds(0, 0, 970, 570);

        jLabel5.setFont(new java.awt.Font("Kristen ITC", 1, 14));
        jLabel5.setForeground(new java.awt.Color(255, 255, 255));
        jLabel5.setText("UserName");
        getContentPane().add(jLabel5);
        jLabel5.setBounds(120, 210, 79, 20);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
       if (jTextField6.getText().equals("") || (jPasswordField1.getText().equals(""))){
            JOptionPane.showMessageDialog(null, "Please insert all details!", "Login Error", 0);
       }
       else{
           String username = jTextField6.getText();
           String password = jPasswordField1.getText();
           boolean flag = controller.login(username, password);
           if (flag) {
                //new Forum(controller, new ForumsViewPanel(controller) ).setSize(693,516);
                _forum= new Forum(controller, this);
               this.setVisible(false);
           }
       }
}//GEN-LAST:event_jButton1ActionPerformed

    private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton1ActionPerformed
           new Register(controller, this).setSize(985,605);
           this.setVisible(false);
    }//GEN-LAST:event_jToggleButton1ActionPerformed

    private void jTextField6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField6ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField6ActionPerformed

    private void jPasswordField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPasswordField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jPasswordField1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JToggleButton jToggleButton1;
    // End of variables declaration//GEN-END:variables

}
